package mc.support.taobao.api;

import mc.support.taobao.api.fields.GetItemPropsFields;
import com.taobao.api.TaobaoRequest;
import com.taobao.api.request.ItempropsGetRequest;
import com.taobao.api.response.ItempropsGetResponse;

/**
 * Created with IntelliJ IDEA. <br/>
 * Author: Francis Yun    <br/>
 * Date: 2014-08-05  <br/>
 */
public class GetItemPropsReq extends AbstractReq<GetItemPropsReq, ItempropsGetResponse> {

    private Long cid;
    private Long pid;
    private Long parentPid;
    private Boolean isKeyProp;
    private Boolean isSaleProp;
    private Boolean isColorProp;
    private Boolean isEnumProp;
    private GetItemPropsFields fields;

    public GetItemPropsReq cid(Long cid) {
        this.cid = cid;
        return this;
    }

    public GetItemPropsReq pid(Long pid) {
        this.pid = pid;
        return this;
    }

    public GetItemPropsReq parentPid(Long parentPid) {
        this.parentPid = parentPid;
        return this;
    }

    public GetItemPropsReq isKeyProp(Boolean isKeyProp) {
        this.isKeyProp = isKeyProp;
        return this;
    }

    public GetItemPropsReq isSaleProp(Boolean isSaleProp) {
        this.isSaleProp = isSaleProp;
        return this;
    }

    public GetItemPropsReq isColorProp(Boolean isColorProp) {
        this.isColorProp = isColorProp;
        return this;
    }

    public GetItemPropsReq isEnumProp(Boolean isEnumProp) {
        this.isEnumProp = isEnumProp;
        return this;
    }

    public GetItemPropsReq fields(GetItemPropsFields fields) {
        this.fields = fields;
        return this;
    }

    @Override
    protected TaobaoRequest toRequest() {
        if ( null == cid ) throw new IllegalArgumentException( "cid is required!" );
        if ( null == fields || ! fields.isSelectedAny() ) throw new IllegalArgumentException( "fields are not specified!" );
        ItempropsGetRequest req = new ItempropsGetRequest();
        req.setCid( cid );
        req.setFields( fields.toString() );
        if ( null != pid ) req.setPid( pid );
        if ( null != parentPid ) req.setParentPid( parentPid );
        if ( null != isKeyProp ) req.setIsKeyProp( isKeyProp );
        if ( null != isSaleProp ) req.setIsSaleProp( isSaleProp );
        if ( null != isColorProp ) req.setIsColorProp( isColorProp );
        if ( null != isEnumProp ) req.setIsEnumProp( isEnumProp );
        return req;
    }

}
